// YaP IRC - Status Text display.
//Copyright (C) 2006  Pierre-Alain DAVID

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.

//This library is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//Lesser General Public License for more details.

//You should have received a copy of the GNU Lesser General Public
//License along with this library; if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA


using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using YaP.Properties;

namespace YaP.Forms
{
    /// <summary>
    /// Description of MonStatus.
    /// </summary>
    public partial class StatusForm
    {
        #region Delegates

        public delegate void SyncFillRichText(string _msg, Color _Fore, Color _Back);

        #endregion

        private MainForm mainContainerForm;


        public StatusForm(MainForm containerForm)
        {
            mainContainerForm = containerForm;
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
            this.Icon  = Icon.FromHandle(Resources.application_side_tree.GetHicon());
            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
        }

        public bool IsNumeric(string s)
        {
            try
            {
                Int32.Parse(s);
                return true;
            }
            catch
            {
                return false;
            }
        }

       

        public void WriteLine(string msg)
        {
            if (!msg.EndsWith("\r\n"))
            {
                msg += "\r\n";
            }
            richBox.AddRTF(msg);
               
            
        }

        private void MonStatusMouseEnter(object sender, System.EventArgs e)
        {
            Opacity = 1.00;
        }

        private void MonStatusMouseLeave(object sender, System.EventArgs e)
        {
            Opacity = 0.20;
        }

        private void MonStatusFormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            if (e.CloseReason != CloseReason.MdiFormClosing)
                e.Cancel = true;
        }

        private void MonStatusLoad(object sender, System.EventArgs e)
        {
            richBox.AddRTF("YaP - version " + mainContainerForm.GetYaPVersion());
        }


        private void RichTextBox1TextChanged(object sender, System.EventArgs e)
        {

            if (mainContainerForm.ActiveMdiChild == this)
            {
                textBox1.Focus();
            }
 
            richBox.SetCaretToEnd();
        }

        private void RichTextBox1Click(object sender, System.EventArgs e)
        {
            textBox1.Focus();
        }

        private void MonStatusShown(object sender, System.EventArgs e)
        {
            textBox1.Focus();
        }

        private void MonStatusActivated(object sender, System.EventArgs e)
        {
            //this.papa.clickswitch(0);
        }

        private void richTextBox1_DoubleClick(object sender, EventArgs e)
        {
            textBox1.Focus();
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char) Keys.Enter)
            {
                e.Handled = true;
                string tosend = textBox1.Text;
                ////history[indexhistory] = textBox1.Text;
                //if (indexhistory < 128)
                //    indexhistory += 1;
                //else
                //    indexhistory = 0;

                //tempindexhistory = indexhistory;

                mainContainerForm.Treatline(tosend, "\tStatus");
                textBox1.Clear();
            }
        }

        private void richTextBox1_SelectionChanged(object sender, EventArgs e)
        {
            //System.Windows.Forms.Clipboard.SetData(System.Windows.Forms.DataFormats.StringFormat, richTextBox1.SelectedText);
        }

        private void richBox_LinkClicked(object sender, LinkClickedEventArgs e)
        {
            Process.Start(e.LinkText);
        }
    }
}